var express = require('express');
var cors = require('cors');
var path = require('path');
// const dotenv = require('dotenv');
// dotenv.config();
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var i18next = require('./i18n');
const middleware = require('i18next-http-middleware');
var brandsRouter = require('./routes/admin/brands');
var seriesRouter = require('./routes/admin/series');
var modelsRouter = require('./routes/admin/models');
var toolsRouter = require('./routes/admin/tools');
var categoriesRouter = require('./routes/admin/categories');
var articlesRouter = require('./routes/admin/articles');
var authorRouter = require('./routes/admin/authors');
var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/uploads', express.static(path.join(__dirname, 'uploads'))); // 由于文件是上传到本地，现在将文件暴露出去供外部访问
app.use(cors());
app.use(middleware.handle(i18next));
app.use('/admin/brands', brandsRouter);
app.use('/admin/series', seriesRouter);
app.use('/admin/models', modelsRouter);
app.use('/admin/tools', toolsRouter);
app.use('/admin/categories', categoriesRouter);
app.use('/admin/articles', articlesRouter);
app.use('/admin/authors', authorRouter);
app.listen(3366, () => {
  console.log('Server is running on port 3366');
  console.log('http://localhost:3366');
});

module.exports = app;
